package main

import "fmt"

func test08() {
	fmt.Println(plus(2,5))
	fmt.Println(swap(66,88))
	fmt.Println(swap2(66,88))
	fmt.Println(plus1(66,88,99,101,152))
	nextInt:=intSeq()
	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(fact(7))
}
//单返回
func plus(a,b int) int {
	return a+b
}
//多返回
func swap(a,b int) (int,int) {
	return b,a
}
//多返回
func swap2(a,b int) (int,int, int) {
	return b,a,25
}
//多参数
func plus1(nums ...int) int {
	total:=0
	for _,num := range nums {
		total+=num
	}
	return total
}

//闭包
func intSeq () func() int{
	i:=0
	return func() int {
		i+=1
		return i
	}
}

//递归
func fact(n int) int{
	if n == 0 {
		return 1
	}
	return n*fact(n-1)
}
